﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Program20
{
    class Program
    {
        public delegate void SayHello(string name);
        public delegate int DelegateCompare<T>(T t1, T t2);
        static void Main(string[] args)
        {
            ////用中文打招呼
            //Hello("阿西吧", SayChinese);
            ////用英文打招呼
            //Hello("Nia", SayEnglish);

            //SayHello say = SayChinese;
            //say("咕噜");

            int[] nums = { 1, 5, 9, 6 };
            Console.WriteLine(GetMax<int>(nums, Compare1));

            string[] strs = { "aaaa", "axjxjx", "aa" };
            Console.WriteLine(GetMax<string>(strs, Compare2));

            Console.ReadLine();
        }

        public static T GetMax<T>(T[] items,DelegateCompare<T> compare)
        {
            T max = items[0];
            for (int i = 0; i < items.Length; i++)
            {
                if (compare(max, items[i]) < 0)
                {
                    max = items[i];
                }
            }
            return max;
        }
        public static int Compare1(int n1,int n2)
        {
            return n1 - n2;
        }

        public static int Compare2(string n1,string n2)
        {
            return n1.Length - n2.Length;
        }


        public static void Hello(string name,SayHello sayHello)
        {
            sayHello(name);
        }
        public static void SayChinese(string name)
        {
            Console.WriteLine("{0}你好，今天天气真不错", name);
        }
        public static void SayEnglish(string name)
        {
            Console.WriteLine("Nice to see you,{0}", name);
        }
    }
}
